<html>
<head><meta charset="utf-8"><title>bare_trait_objects 2021 · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html">bare_trait_objects 2021</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="211101435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/211101435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#211101435">(Sep 24 2020 at 08:20)</a>:</h4>
<p>Can we change trait objects without <code>dyn</code> to either deny by default or even a hard error in the next edition?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">test</span><span class="p">(</span><span class="n">_</span>: <span class="kp">&amp;</span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kt">u32</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
</code></pre></div>

<div class="codehilite"><pre><span></span><code>warning: trait objects without an explicit `dyn` are deprecated
 --&gt; src/lib.rs:1:17
  |
1 | pub fn test(_: &amp;Iterator&lt;Item = u32&gt;) {}
  |                 ^^^^^^^^^^^^^^^^^^^^ help: use `dyn`: `dyn Iterator&lt;Item = u32&gt;`
  |
</code></pre></div>



<a name="211101509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/211101509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#211101509">(Sep 24 2020 at 08:21)</a>:</h4>
<p>changing it to a hard error allows us to more easily improve the error message for <code>T: Iterator&lt;Item=Result&lt;V, E&gt; + 'a&gt;</code></p>



<a name="211101952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/211101952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#211101952">(Sep 24 2020 at 08:26)</a>:</h4>
<p>I think we could move to deny-by-default in this edition and definitely to a hard error in the next one</p>



<a name="211178408"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/211178408" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#211178408">(Sep 24 2020 at 19:25)</a>:</h4>
<p>I think hard error in vNext is allowed since we're currently warning about it in vCurrent.  I'd personally be fine with it.</p>



<a name="211179010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/211179010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#211179010">(Sep 24 2020 at 19:30)</a>:</h4>
<p>The warning just says it's deprecated, so IMO it's too aggressive to make that an error in the current edition.</p>



<a name="211179055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/211179055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#211179055">(Sep 24 2020 at 19:30)</a>:</h4>
<p>But I'm fine with changing that in 2021</p>



<a name="211182293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/211182293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#211182293">(Sep 24 2020 at 19:59)</a>:</h4>
<p>Yeah, I think we can go lint-warn -&gt; error in one edition, we don't need to go lint-warn -&gt; lint-deny -&gt; error over two editions.</p>



<a name="211188976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/211188976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#211188976">(Sep 24 2020 at 20:59)</a>:</h4>
<p>The original edition RFC specifically said two steps from syntax allowed to syntax not allowed.</p>



<a name="211190606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/211190606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#211190606">(Sep 24 2020 at 21:12)</a>:</h4>
<p>As I understand it that meant two edition steps, which would be the case here. Allowed in 2015, linted in 2018, forbidden in 2021</p>



<a name="211405620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/211405620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#211405620">(Sep 27 2020 at 08:39)</a>:</h4>
<p>is the lint warn by default now? it wasn't for a long time, so i'm not sure you can really say "linted in 2018" if it's "a lint exists but it's allowed by default".</p>
<p>(that said i'm weakly in favor of the change)</p>



<a name="211405635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/211405635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#211405635">(Sep 27 2020 at 08:40)</a>:</h4>
<p>afaik we always had it on warn in edition 2018?</p>



<a name="211405673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/211405673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#211405673">(Sep 27 2020 at 08:40)</a>:</h4>
<p>or am I missing something here</p>



<a name="211405756"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/211405756" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#211405756">(Sep 27 2020 at 08:43)</a>:</h4>
<p>i know at the start of rust 2018 you had to use rust_2018_idioms to get it, but perhaps since then it changed to warn by default.</p>



<a name="211405821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/211405821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#211405821">(Sep 27 2020 at 08:44)</a>:</h4>
<p>it was changed to warn by default in 1.37 <a href="https://github.com/rust-lang/rust/pull/61203">https://github.com/rust-lang/rust/pull/61203</a></p>



<a name="212426842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/212426842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#212426842">(Oct 06 2020 at 13:27)</a>:</h4>
<p>The 2021 RFC states that 2018 Idiom lints will become warn-by-default (before 2021) and then deny-by-default (&gt;= 2021)</p>



<a name="214234117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214234117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214234117">(Oct 22 2020 at 19:09)</a>:</h4>
<p>Just posting this as food for thought: <a href="https://github.com/rust-lang/rust/pull/77502#discussion_r499172677">https://github.com/rust-lang/rust/pull/77502#discussion_r499172677</a><br>
Diagnostics for const generics could be improved if we forbid <code>bare_trait_objects</code> altogether, because they're really awkward to disambiguate from expressions that have not been <code>{}</code>'d.</p>



<a name="214234200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214234200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214234200">(Oct 22 2020 at 19:09)</a>:</h4>
<p>This would mean changing it from an idiom lint to forbidden syntax altogether, though.</p>



<a name="214234341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214234341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214234341">(Oct 22 2020 at 19:10)</a>:</h4>
<p>I would personally be fine doing that in 2021 -- const generics definitely seem important enough.</p>



<a name="214235136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214235136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214235136">(Oct 22 2020 at 19:16)</a>:</h4>
<p>This has been warn for long enough in 2018 that I have no problems with moving this to a hard error in 2021.  It makes good sense to me.</p>



<a name="214240063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214240063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214240063">(Oct 22 2020 at 19:54)</a>:</h4>
<p>Hmm this reminds me that one of the things we plan to do for 2021 edition is making the idiom lints warn by default</p>



<a name="214240073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214240073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214240073">(Oct 22 2020 at 19:54)</a>:</h4>
<p>we should probably...do that</p>



<a name="214240091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214240091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214240091">(Oct 22 2020 at 19:54)</a>:</h4>
<p>I too would be in favor  of removing bare trait objects in 2021</p>



<a name="214240109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214240109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214240109">(Oct 22 2020 at 19:55)</a>:</h4>
<p>we need to get a bit more organized about some of these changes</p>



<a name="214240157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214240157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214240157">(Oct 22 2020 at 19:55)</a>:</h4>
<p>I'm not sure if we need an RFC or what precisely for this sort of change, seems like maybe an RFC</p>



<a name="214240397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214240397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214240397">(Oct 22 2020 at 19:57)</a>:</h4>
<p>I can write an RFC to go through the formal process if everyone's generally in favour.</p>



<a name="214242253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214242253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214242253">(Oct 22 2020 at 20:11)</a>:</h4>
<p><span class="user-mention" data-user-id="121053">@varkor</span> if you write up a quick proposal on lang-team repo we can discuss in a triage meeting perhaps, or maybe people will chime in here</p>



<a name="214242333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214242333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214242333">(Oct 22 2020 at 20:12)</a>:</h4>
<p>Let's see if this thread gets any more comments; otherwise I'll make a proposal <span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span></p>



<a name="214260639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214260639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214260639">(Oct 22 2020 at 23:42)</a>:</h4>
<p>I'd be in favor of making this a hard error in 2021, yes.</p>



<a name="214260643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214260643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214260643">(Oct 22 2020 at 23:42)</a>:</h4>
<p>As long as we don't make it a hard error in previous editions.</p>



<a name="214260649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214260649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214260649">(Oct 22 2020 at 23:42)</a>:</h4>
<p>(which means the parsers for those still have to handle it.)</p>



<a name="214297171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214297171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214297171">(Oct 23 2020 at 10:36)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/bare_trait_objects.202021/near/214260649">said</a>:</p>
<blockquote>
<p>(which means the parsers for those still have to handle it.)</p>
</blockquote>
<p>The way I see it, IIUC, is that older edition may thus still be required to provide <code>{ ... }</code> to disambiguate const generic params, but from 2021 edition onwards that part can be skipped thanks to bare trait objects syntax being rejected altogether.</p>



<a name="214297197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214297197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214297197">(Oct 23 2020 at 10:37)</a>:</h4>
<p>(deleted)</p>



<a name="214299325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214299325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214299325">(Oct 23 2020 at 11:05)</a>:</h4>
<p>That's not the problem. Const arguments will always require <code>{}</code>, but we can provide better recovery messages if bare trait objects are forbidden. This will mean we will get better diagnostics in 2021 edition, but the syntax for const generics itself won't change.</p>



<a name="214784304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/bare_trait_objects%202021/near/214784304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/bare_trait_objects.202021.html#214784304">(Oct 28 2020 at 00:55)</a>:</h4>
<p>I've created a meeting proposal: <a href="https://github.com/rust-lang/lang-team/issues/65">https://github.com/rust-lang/lang-team/issues/65</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>